<!DOCTYPE html>
<html lang="zh-CN">
  <head>
	  <%layout("/WEB-INF/view/common/inc/admin_head.html",{title:'添加', styles:'bootstrap,font-awesome,animate,style,dtvalidate,layui,chosen'}){%>
	  <style type="text/css">
		  body{padding-top:10px;}
		  .radio{
			  vertical-align:middle;
			  margin-top:5px;
		  }
	  </style>
	  <%}%>
  </head>
  <body>
  <div class="wrapper wrapper-content">
	  <div class="row">
		  <div class="col-sm-12">
			  <div class="col-sm-offset-1 col-sm-10" style="margin-left: -10px;width: 100%;">
				  <button type="button" class="return-btn btn btn-w-m btn-primary">返回</button>
				  <div style="border-color: #e7eaec;border-image: none;border-style: solid solid none;border-width: 4px 0px;padding-bottom: 15px;margin-top: 10px;" ></div>
			  </div>
		  </div>
	  </div>
  </div>
	<!-- START 内容部分 -->
	<div class="container">
		<form class="form-horizontal" id="info-form" method="post" autocomplete="off">

			<input type="hidden" name="id" id="id" value="${bill.id}">
			<div class="form-group">
				<label class="col-sm-2 control-label text-right">发票图片</label>
				<div class="col-sm-6">
					<button  class="layui-btn layui-btn-sm import-btn" style="margin-left: -2px" type="button" id="import-btn"  name="import-btn">
						<i class="layui-icon"></i>上传发票图片
					</button>
					<input type="hidden" id="billImg"  name="billImg" value="${bill.billImg}">
				</div>
			</div>

			<div class="form-group">
				<label class="col-sm-2 control-label text-right">供应商:</label>
				<div class="col-sm-8">
					<input type="text" id="supplierName" name="supplierName" value="${bill.supplierName}" class="form-control"  />
				</div>
			</div>
			<div class="form-group">
				<label class="control-label col-sm-2">柜号:</label>
				<div class="col-sm-8">
					<input type="text" id="createPlanNo" readonly name="createPlanNo" value="${bill.createPlanNo}" class="form-control"  />
				</div>
			</div>
			<div class="form-group">
				<label class="control-label col-sm-2">发票号码:</label>
				<div class="col-sm-8">
					<input type="text" id="billNumber" name="billNumber" value="${bill.billNumber}" class="form-control"  />
				</div>
			</div>
			<div class="form-group">
				<label class="control-label col-sm-2">发票代码:</label>
				<div class="col-sm-8">
					<input type="text" id="billCode" name="billCode" value="${bill.billCode}" class="form-control"  />
				</div>
			</div>
			<div class="form-group">
				<label class="control-label col-sm-2">不含税金额:</label>
				<div class="col-sm-8">
					<input type="text" id="billPrice" name="billPrice" value="${bill.billPrice}"  class="form-control"  />
				</div>
			</div>
			<div class="form-group">
				<label class="control-label col-sm-2">税额:</label>
				<div class="col-sm-8">
					<input type="text" id="billTax" name="billTax" value="${bill.billTax}" class="form-control"  />
				</div>
			</div>
			<div class="form-group">
				<label class="control-label col-sm-2">金额:</label>
				<div class="col-sm-8">
					<input type="text" id="billMoney" name="billMoney"  value="${bill.billMoney}" class="form-control"  />
				</div>
			</div>
			<div class="form-group">
				<div class="col-sm-offset-2 col-sm-10">
					<button type="button" class="save-btn btn btn-primary">
						<i class="fa fa-save"></i> 保存
					</button>
				</div>
			</div>
		</form>
	</div>
	<!-- END 内容部分 -->
  </div>
	<!-- START 公共脚本 -->
    <%layout("/WEB-INF/view/common/inc/admin_js.html",{modules:'jquery,bootstrap,dtvalidate,dtvalidate-lang-zh_cn,laydate,layer,chosen,chosen-demo,layui,upload'}){}%>
	<!-- END 公共脚本 -->

	<script>
		layui.use('upload', function(){
			var upload = layui.upload;
			upload.render({
				elem: '#import-btn', //绑定元素,
				accept:'file',
				url: '/sea/supply/bill/import/', //上传接口
				data:{},
				before:function () {
					layer.load(1, {
						shade: [0.1,'#fff'] //0.1透明度的白色背景
					});
				}
				,done: function(data){
					if( data.ok ){
						layer.msg(data.msg,{icon: 1,time: 1500},function(){
							//刷新页面
							$("#supplierName").val(data.data.supplierName);
							$("#billImg").val(data.data.billImg);
							$("#billCode").val(data.data.billCode);
							$("#billNumber").val(data.data.billNumber);
							$("#billPrice").val(data.data.billPrice);
							$("#billTax").val(data.data.billTax);
							$("#billMoney").val(data.data.billMoney);
							layer.closeAll();
						});
					}else{
						layer.msg(data.msg,{icon: 0,time: 5000},function () {
							layer.closeAll();
						});

					}
				}
				,error: function(){
					//请求异常回调
					layer.closeAll();
				}
			});
		});
	var cvalidator;
	$(function(){
		//初始化验证器
		cvalidator = $.fn.dlshouwen.validator.init($('#info-form'));
		//提交表单
		$('.save-btn').on('click',function(){

			//数据提交
			$.post('/sea/supply/bill/usave.do',$('#info-form').serialize(),function(data){
				if( data.ok ){
					parent.layer.msg(data.msg,{icon:1,time:1500,shade: [0.8, '#393D49']}, function(){
						parent.$relatedTable.bootstrapTable('refresh');
						parent.layer.close(parent.layer.getFrameIndex(window.name)); //关闭弹窗
					});
				}else{
					parent.layer.msg(data.msg,{icon: 0,time:1500,shade: [0.8, '#393D49']});
				}
			});
		});



    });



	$("#productBigClassId").change(function () {
		var parentId=$("#productBigClassId").val();
		getCategory(parentId,1);
	});
	$("#productMidClassId").change(function () {
		var parentId=$("#productMidClassId").val();
		getCategory(parentId,2);
	});

	function getCategory(parentId,type) {
		$.ajax({
			url:'/sea/product/category/findByParentId',
			data:{
				id:parentId
			},
			type:'post',
			success:function (data) {
				var list=data;
				if(list.length>0){
					var category='<option value="">全部分类</option>';
					for(var i=0;i<list.length;i++){
						category+='<option value="'+list[i].id+'">'+list[i].categoryName+'</option>';
					}
					if(type=='1') {
						$("#productMidClassId").html(category);
					}
					if(type=='2'){
						$("#productClassId").html(category);
					}
				}
			}
		});
		//返回

	}
	$('.return-btn').on('click',function(){
		parent.layer.close(parent.layer.getFrameIndex(window.name)); //关闭弹窗
	});
    </script>
  </body>
</html>